package com.cssw.fyzb.tps.api.im;

import com.cssw.fyzb.tps.service.im.GroupService;
import com.cssw.fyzb.tps.service.im.common.ImHttpComm;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author Jian Qin.
 */
@Function(description = "解散群组", parameters = {
        @Parameter(name = "groupId", type = Type.String, description = "群组 ID"),
})
@Component
public class DestroyGroup implements Action {
    @Autowired
    private GroupService groupService;

    @Override
    public Response execute(Request request) throws Exception {
        ImHttpComm.ImResult result = groupService.destroyGroup(
                request.getString("groupId"));
        if(result.getErrorCode() == 0){
            return Response.success();
        }else{
            return Response.fail(result.getErrorInfo(), result.getErrorCode());
        }
    }
}
